﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using Repository.Pattern.Repositories;
using System.Threading.Tasks;
using WebApp.Models;
namespace WebApp.Repositories
{
  /// <summary>
  /// File: CustomerRepository.cs
  /// Purpose: The repository and unit of work patterns are intended
  /// to create an abstraction layer between the data access layer and
  /// the business logic layer of an application.
  /// Created Date: 3/25/2020 9:48:00 PM
  /// Author: neo.zhu
  /// Tools: SmartCode MVC5 Scaffolder for Visual Studio 2017
  /// Copyright (c) 2012-2018 All Rights Reserved
  /// </summary>
  public static class CustomerRepository
  {
    public static async Task<IEnumerable<CustomerWaterRecord>> GetCustomerWaterRecordsByCustomerIdAsync(this IRepositoryAsync<Customer> repository, int customerid)
=> await repository.GetRepositoryAsync<CustomerWaterRecord>()
.Queryable()
.Where(n => n.CustomerId == customerid)
.ToListAsync();

    public static async Task<IEnumerable<CustomerWaterMeter>> GetWaterMetersByCustomerIdAsync(this IRepositoryAsync<Customer> repository, int customerid)
=> await repository.GetRepositoryAsync<CustomerWaterMeter>()
        .Queryable()
        .Include(x => x.Customer)
        .Where(n => n.CustomerId == customerid)
        .ToListAsync();

    public static async Task<IEnumerable<CustomerWaterQuota>> GetWaterQuotasByCustomerIdAsync(this IRepositoryAsync<Customer> repository, int customerid)
=> await repository.GetRepositoryAsync<CustomerWaterQuota>()
        .Queryable()
        .Include(x => x.Customer)
        .Where(n => n.CustomerId == customerid)
        .ToListAsync();


  }
}



